package com.dhcc.sdc.busi.controller;


import java.util.List;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;



import com.dhcc.sdc.busi.entity.SdcBusiContraindicationDtlEntity;
import com.dhcc.sdc.busi.service.ISdcBusiContraindicationDtlService;


/**
 * 禁忌症评估明细表
 * 
 * @ClassName: SdcBusiContraindicationDtlController
 * @Description: TODO
 * @author sunyingjie
 * @date 2022-09-20 14:17:04
 */
@Controller
@RequestMapping("${sys.backendPath}/sdc/sdcbusicontraindicationdtl")
public class SdcBusiContraindicationDtlController extends BaseController {

	private String PREFIX = "/backend/sdc/sdcbusicontraindicationdtl/";

	@Autowired
	private ISdcBusiContraindicationDtlService sdcBusiContraindicationDtlService;
	

    /**
     * 跳转到禁忌症评估明细表列表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "sdcbusicontraindicationdtl.html";
    }
	
    /**
     * 跳转到新增禁忌症评估明细表
     */
    @RequestMapping("/to_add")
    public String toAdd() {
        return PREFIX + "sdcbusicontraindicationdtl_add.html";
    }
	
	/**
     * 跳转到修改禁忌症评估明细表
     */
    @RequestMapping("/to_update/{sdcBusiContraindicationDtlId}")
    public String toUpdate(@PathVariable Long sdcBusiContraindicationDtlId, Model model) {
        SdcBusiContraindicationDtlEntity sdcBusiContraindicationDtl = this.sdcBusiContraindicationDtlService.selectById(sdcBusiContraindicationDtlId);
        model.addAttribute("sdcBusiContraindicationDtl",sdcBusiContraindicationDtl);
        return PREFIX + "sdcbusicontraindicationdtl_edit.html";
    }

    /**
     * 获取禁忌症评估明细表列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam Map<String, Object> params) {
		Page<SdcBusiContraindicationDtlEntity> page = new PageFactory<SdcBusiContraindicationDtlEntity>().defaultPage();
        List<SdcBusiContraindicationDtlEntity> result = this.sdcBusiContraindicationDtlService.page(page,params);
        page.setRecords((List<SdcBusiContraindicationDtlEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增禁忌症评估明细表
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(SdcBusiContraindicationDtlEntity sdcBusiContraindicationDtl) {
        if (CommonUtil.isOneEmpty(sdcBusiContraindicationDtl)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        sdcBusiContraindicationDtl.insert();
        return R.ok();
    }

    /**
     * 删除禁忌症评估明细表
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long sdcBusiContraindicationDtlId) {
	
        this.sdcBusiContraindicationDtlService.deleteById(sdcBusiContraindicationDtlId);

        return R.ok();
    }

    /**
     * 修改禁忌症评估明细表
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(SdcBusiContraindicationDtlEntity sdcBusiContraindicationDtl) {
        if (CommonUtil.isOneEmpty(sdcBusiContraindicationDtl)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        SdcBusiContraindicationDtlEntity old = this.sdcBusiContraindicationDtlService.selectById(sdcBusiContraindicationDtl.getId());

        old.setEpisodeId(sdcBusiContraindicationDtl.getEpisodeId());
        old.setContraindicationId(sdcBusiContraindicationDtl.getContraindicationId());
        old.setItemId(sdcBusiContraindicationDtl.getItemId());
        old.setKeyWords(sdcBusiContraindicationDtl.getKeyWords());
        old.setMannul(sdcBusiContraindicationDtl.getMannul());
        old.setStatus(sdcBusiContraindicationDtl.getStatus());
        old.setKeyWordsfrom(sdcBusiContraindicationDtl.getKeyWordsfrom());
        old.setTriggerDate(sdcBusiContraindicationDtl.getTriggerDate());
        old.updateAllColumnById();
        return R.ok();
    }
	
}
